import carddeck

class Hand(object):

    def __init__(self, card1=None, card2=None):
        self._cards = []
        self._cards.append(card1)
        self._cards.append(card2)

    def _sort(self):
        self._cards = sorted(self._cards, key=lambda card: card.value, reverse=True)

    def _get_cards(self):
        return self._cards
    cards = property(_get_cards)

    # contains logic for best Ace Value
    def _get_total(self):
        total = 0
        for card in self._cards:
            if card:
                total += card.value
        if total > 21:
            for card in self._cards:
                if card:
                    if card.value == 11:
                        card.value = 1
                        total -= 10
        return total
    total = property(_get_total)

    def deal_card(self, card):
        self._cards.append(card)

    def __str__(self):
        returnMe = ""
        for card in self._cards:
            if card:
                returnMe += "\n" + card.__str__()
        returnMe += "\n"
        return returnMe
